home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / CopyPanel.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  12KB  |  477 lines

  1. /*
  2. **    CopyPanel.c
  3. **
  4. **    Editing panel for configuration copying
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_SERIAL,GAD_MODEM,GAD_SCREEN,GAD_TERMINAL,GAD_EMULATION,
  13.         GAD_CLIPBOARD,GAD_CAPTURE,GAD_COMMANDS,GAD_MISC,GAD_PATHS,GAD_TRANSFER,
  14.         GAD_TRANSLATION,GAD_KEYMACROS,GAD_CURSORKEYS,GAD_FASTMACROS,GAD_COPYTOALL,
  15.         GAD_DEFAULT,GAD_ALL,GAD_CLEAR,GAD_USE,GAD_CANCEL };
  16.  
  17. enum    {    COPY_MAIN_CONFIG,COPY_DEFAULTS };
  18.  
  19. STATIC ULONG    Bits        = 0;
  20.  
  21. STATIC BYTE    CopyMode    = COPY_MAIN_CONFIG,
  22.         AllFileSettings    = FALSE;
  23.  
  24. STATIC STRPTR    CopyType[3];
  25.  
  26. STATIC struct Gadget *
  27. CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList)
  28. {
  29.     struct Gadget        *Gadget;
  30.     struct NewGadget     NewGadget;
  31.     UWORD             Counter = 0;
  32.  
  33.     LocalizeString(CopyType,MSG_COPYPANEL_COPY_GLOBAL_CONFIG_MSG,MSG_COPYPANEL_COPY_GLOBAL_DEFAULTS_MSG);
  34.  
  35.     SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
  36.  
  37.     memset(&NewGadget,0,sizeof(struct NewGadget));
  38.  
  39.     if(Gadget = CreateContext(GadgetList))
  40.     {
  41.         WORD i,RightColumn;
  42.  
  43.         SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_COPYPANEL_SERIAL_GAD,MSG_COPYPANEL_COMMANDS_GAD));
  44.  
  45.         RightColumn = SZ_LeftOffsetDelta(MSG_COPYPANEL_MISCELLANEOUS_GAD,MSG_COPYPANEL_TO_ALL_ENTRIES_GAD);
  46.  
  47.         for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
  48.         {
  49.             NewGadget . ng_GadgetText    = LocaleString(MSG_COPYPANEL_SERIAL_GAD + i - GAD_SERIAL);
  50.             NewGadget . ng_GadgetID        = Counter;
  51.             NewGadget . ng_Flags        = 0;
  52.  
  53.             if(i == GAD_MISC)
  54.             {
  55.                 SZ_AddLeftOffset(RightColumn);
  56.  
  57.                 GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  58.                     SZ_Adjust,    TRUE,
  59.                     SZ_AutoWidth,    TRUE,
  60.                     SZ_NewColumn,    TRUE,
  61.  
  62.                     GTCB_Checked,    Bits & (1 << (i - GAD_SERIAL)),
  63.                 TAG_DONE);
  64.             }
  65.             else
  66.             {
  67.                 GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  68.                     SZ_Adjust,    TRUE,
  69.                     SZ_AutoWidth,    TRUE,
  70.  
  71.                     GTCB_Checked,    Bits & (1 << (i - GAD_SERIAL)),
  72.                 TAG_DONE);
  73.             }
  74.         }
  75.  
  76.         NewGadget . ng_GadgetText    = LocaleString(MSG_COPYPANEL_TO_ALL_ENTRIES_GAD);
  77.         NewGadget . ng_GadgetID        = Counter;
  78.  
  79.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  80.             SZ_Adjust,    TRUE,
  81.             SZ_AutoWidth,    TRUE,
  82.  
  83.             GTCB_Checked,    FALSE,
  84.         TAG_DONE);
  85.  
  86.         SZ_ResetMaxWidth();
  87.  
  88.         SZ_UpdateMaxWidth(CYCLE_KIND,NULL,0,CopyType);
  89.  
  90.         SZ_SetWidth(SZ_ResetMaxWidth());
  91.  
  92.         NewGadget . ng_GadgetText    = LocaleString(MSG_COPYPANEL_COPY_TYPE_GAD);
  93.         NewGadget . ng_GadgetID        = Counter;
  94.  
  95.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  96.             SZ_Adjust,    TRUE,
  97.             SZ_AutoWidth,    TRUE,
  98.             SZ_AlignBottom,    TRUE,
  99.             SZ_AlignCentre,    TRUE,
  100.             SZ_AlignExtra,    TRUE,
  101.  
  102.             GTCY_Labels,    CopyType,
  103.             GTCY_Active,    CopyMode,
  104.         TAG_DONE);
  105.  
  106.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_COPYPANEL_ALL_GAD),0,NULL);
  107.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_COPYPANEL_CLEAR_GAD),0,NULL);
  108.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
  109.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  110.  
  111.         SZ_SetWidth(SZ_ResetMaxWidth());
  112.  
  113.         NewGadget . ng_GadgetText    = LocaleString(MSG_COPYPANEL_ALL_GAD);
  114.         NewGadget . ng_GadgetID        = Counter;
  115.         NewGadget . ng_Flags        = PLACETEXT_IN;
  116.  
  117.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  118.             SZ_Adjust,    TRUE,
  119.             SZ_AutoWidth,    TRUE,
  120.             SZ_AlignExtra,    TRUE,
  121.             SZ_AlignLeft,    TRUE,
  122.             SZ_AlignBottom,    TRUE,
  123.         TAG_DONE);
  124.  
  125.         NewGadget . ng_GadgetText    = LocaleString(MSG_COPYPANEL_CLEAR_GAD);
  126.         NewGadget . ng_GadgetID        = Counter;
  127.  
  128.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  129.             SZ_Adjust,    TRUE,
  130.             SZ_AutoWidth,    TRUE,
  131.             SZ_AlignRight,    TRUE,
  132.         TAG_DONE);
  133.  
  134.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_USE_GAD);
  135.         NewGadget . ng_GadgetID        = Counter;
  136.  
  137.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  138.             SZ_Adjust,    TRUE,
  139.             SZ_AutoWidth,    TRUE,
  140.             SZ_AlignLeft,    TRUE,
  141.             SZ_AlignBottom,    TRUE,
  142.         TAG_DONE);
  143.  
  144.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_CANCEL_GAD);
  145.         NewGadget . ng_GadgetID        = Counter;
  146.  
  147.         GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  148.             SZ_Adjust,    TRUE,
  149.             SZ_AutoWidth,    TRUE,
  150.             SZ_AlignRight,    TRUE,
  151.         TAG_DONE);
  152.     }
  153.  
  154.     return(Gadget);
  155. }
  156.  
  157. STATIC VOID __regargs
  158. CopyConfig(struct Configuration *MyConfig,BYTE Part)
  159. {
  160.     STATIC LONG TypeMappings[15][2] =
  161.     {
  162.         GAD_SERIAL,        PREF_SERIAL,
  163.         GAD_MODEM,        PREF_MODEM,
  164.         GAD_SCREEN,        PREF_SCREEN,
  165.         GAD_TERMINAL,        PREF_TERMINAL,
  166.         GAD_EMULATION,        PREF_EMULATION,
  167.         GAD_CLIPBOARD,        PREF_CLIP,
  168.         GAD_CAPTURE,        PREF_CAPTURE,
  169.         GAD_COMMANDS,        PREF_COMMAND,
  170.         GAD_MISC,        PREF_MISC,
  171.         GAD_PATHS,        PREF_PATH,
  172.         GAD_TRANSFER,        PREF_TRANSFER,
  173.         GAD_TRANSLATION,    PREF_FILE,
  174.         GAD_KEYMACROS,        PREF_FILE,
  175.         GAD_CURSORKEYS,        PREF_FILE,
  176.         GAD_FASTMACROS,        PREF_FILE
  177.     };
  178.  
  179.     LONG i,PrefType;
  180.     APTR Data;
  181.  
  182.     for(i = 0 ; i < 15 ; i++)
  183.     {
  184.         if(Part == TypeMappings[i][0])
  185.         {
  186.             PrefType = TypeMappings[i][1];
  187.  
  188.             break;
  189.         }
  190.     }
  191.  
  192.     Data = GetConfigEntry(MyConfig,PrefType);
  193.  
  194.     if(CopyMode == COPY_MAIN_CONFIG)
  195.     {
  196.         if(CreateConfigEntry(MyConfig,PrefType))
  197.         {
  198.             if(!Data)
  199.                 ResetConfigEntry(MyConfig,PrefType,FALSE);
  200.  
  201.             switch(Part)
  202.             {
  203.                 case GAD_SERIAL:
  204.  
  205.                     memcpy(MyConfig -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  206.                     break;
  207.  
  208.                 case GAD_MODEM:
  209.  
  210.                     memcpy(MyConfig -> ModemConfig,Config -> ModemConfig,sizeof(struct ModemSettings));
  211.                     break;
  212.  
  213.                 case GAD_SCREEN:
  214.  
  215.                     memcpy(MyConfig -> ScreenConfig,Config -> ScreenConfig,sizeof(struct ScreenSettings));
  216.                     break;
  217.  
  218.                 case GAD_TERMINAL:
  219.  
  220.                     memcpy(MyConfig -> TerminalConfig,Config -> TerminalConfig,sizeof(struct TerminalSettings));
  221.                     break;
  222.  
  223.                 case GAD_EMULATION:
  224.  
  225.                     memcpy(MyConfig -> EmulationConfig,Config -> EmulationConfig,sizeof(struct EmulationSettings));
  226.                     break;
  227.  
  228.                 case GAD_CLIPBOARD:
  229.  
  230.                     memcpy(MyConfig -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings));
  231.                     break;
  232.  
  233.                 case GAD_CAPTURE:
  234.  
  235.                     memcpy(MyConfig -> CaptureConfig,Config -> CaptureConfig,sizeof(struct CaptureSettings));
  236.                     break;
  237.  
  238.                 case GAD_COMMANDS:
  239.  
  240.                     memcpy(MyConfig -> CommandConfig,Config -> CommandConfig,sizeof(struct CommandSettings));
  241.                     break;
  242.  
  243.                 case GAD_MISC:
  244.  
  245.                     memcpy(MyConfig -> MiscConfig,Config -> MiscConfig,sizeof(struct MiscSettings));
  246.                     break;
  247.  
  248.                 case GAD_PATHS:
  249.  
  250.                     memcpy(MyConfig -> PathConfig,Config -> PathConfig,sizeof(struct PathSettings));
  251.                     break;
  252.  
  253.                 case GAD_TRANSFER:
  254.  
  255.                     memcpy(MyConfig -> TransferConfig,Config -> TransferConfig,sizeof(struct TransferSettings));
  256.                     break;
  257.  
  258.                 case GAD_TRANSLATION:
  259.  
  260.                     strcpy(MyConfig -> FileConfig -> TranslationFileName,Config -> FileConfig -> TranslationFileName);
  261.                     break;
  262.  
  263.                 case GAD_KEYMACROS:
  264.  
  265.                     strcpy(MyConfig -> FileConfig -> MacroFileName,Config -> FileConfig -> MacroFileName);
  266.                     break;
  267.  
  268.                 case GAD_CURSORKEYS:
  269.  
  270.                     strcpy(MyConfig -> FileConfig -> CursorFileName,Config -> FileConfig -> CursorFileName);
  271.                     break;
  272.  
  273.                 case GAD_FASTMACROS:
  274.  
  275.                     strcpy(MyConfig -> FileConfig -> FastMacroFileName,Config -> FileConfig -> FastMacroFileName);
  276.                     break;
  277.             }
  278.         }
  279.     }
  280.     else
  281.     {
  282.         if(Data && (PrefType != PREF_FILE || AllFileSettings))
  283.             DeleteConfigEntry(MyConfig,PrefType);
  284.     }
  285. }
  286.  
  287. BYTE
  288. CopyPanel(struct Configuration *MyConfig,BYTE Selective)
  289. {
  290.     struct Window    *PanelWindow;
  291.     struct Gadget    *GadgetList;
  292.     struct Gadget    *GadgetArray[GAD_CANCEL + 1];
  293.     BYTE         MadeChanges = FALSE;
  294.  
  295.     if(CreateAllGadgets(GadgetArray,&GadgetList))
  296.     {
  297.         if(PanelWindow = OpenWindowTags(NULL,
  298.             WA_Left,    GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
  299.             WA_Top,        GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight())    / 2,
  300.             WA_Width,    SZ_GetWindowWidth(),
  301.             WA_Height,    SZ_GetWindowHeight(),
  302.  
  303.             WA_Activate,    TRUE,
  304.             WA_DragBar,    TRUE,
  305.             WA_DepthGadget,    TRUE,
  306.             WA_RMBTrap,    TRUE,
  307.             WA_DepthGadget,    TRUE,
  308.             WA_CloseGadget,    TRUE,
  309.             WA_CustomScreen,Window -> WScreen,
  310.             WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | BUTTONIDCMP | CHECKBOXIDCMP,
  311.             WA_Title,    LocaleString(MSG_COPYPANEL_COPY_CONFIG_TXT),
  312.         TAG_DONE))
  313.         {
  314.             struct IntuiMessage    *Massage;
  315.             ULONG             IClass,Code;
  316.             struct Gadget        *Gadget;
  317.             BYTE             Terminated = FALSE;
  318.             LONG             i;
  319.  
  320.             GuideContext(CONTEXT_COPY);
  321.  
  322.             PushWindow(PanelWindow);
  323.  
  324.             AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  325.             RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  326.             GT_RefreshWindow(PanelWindow,NULL);
  327.  
  328.             if(!MyConfig)
  329.             {
  330.                 GT_SetGadgetAttrs(GadgetArray[GAD_COPYTOALL],PanelWindow,NULL,
  331.                     GTCB_Checked,    TRUE,
  332.                     GA_Disabled,    TRUE,
  333.                 TAG_DONE);
  334.             }
  335.  
  336.             ClrSignal(SIG_BREAK);
  337.  
  338.             while(!Terminated)
  339.             {
  340.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  341.                     break;
  342.  
  343.                 while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  344.                 {
  345.                     IClass    = Massage -> Class;
  346.                     Code    = Massage -> Code;
  347.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  348.  
  349.                     GT_ReplyIMsg(Massage);
  350.  
  351.                     KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
  352.  
  353.                     if(IClass == IDCMP_CLOSEWINDOW)
  354.                         Terminated = TRUE;
  355.  
  356.                     if(IClass == IDCMP_GADGETUP)
  357.                     {
  358.                         switch(Gadget -> GadgetID)
  359.                         {
  360.                             case GAD_ALL:
  361.  
  362.                                 for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
  363.                                 {
  364.                                     GT_SetGadgetAttrs(GadgetArray[i],PanelWindow,NULL,
  365.                                         GTCB_Checked,    TRUE,
  366.                                     TAG_DONE);
  367.                                 }
  368.  
  369.                                 break;
  370.  
  371.                             case GAD_CLEAR:
  372.  
  373.                                 for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
  374.                                 {
  375.                                     GT_SetGadgetAttrs(GadgetArray[i],PanelWindow,NULL,
  376.                                         GTCB_Checked,    FALSE,
  377.                                     TAG_DONE);
  378.                                 }
  379.  
  380.                                 break;
  381.  
  382.                             case GAD_DEFAULT:
  383.  
  384.                                 CopyMode = Code;
  385.                                 break;
  386.  
  387.                             case GAD_USE:
  388.  
  389.                                 Bits = NULL;
  390.  
  391.                                 if(SZ_GetChecked(GadgetArray[GAD_COPYTOALL]))
  392.                                 {
  393.                                     LONG j;
  394.  
  395.                                     AllFileSettings = TRUE;
  396.  
  397.                                     for(i = GAD_TRANSLATION ; i <= GAD_FASTMACROS ; i++)
  398.                                         AllFileSettings &= SZ_GetChecked(GadgetArray[i]);
  399.  
  400.                                     if(Selective)
  401.                                     {
  402.                                         for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
  403.                                         {
  404.                                             if(SZ_GetChecked(GadgetArray[i]))
  405.                                             {
  406.                                                 for(j = 0 ; j < NumPhoneEntries ; j++)
  407.                                                 {
  408.                                                     if(Phonebook[j] -> Count != -1)
  409.                                                         CopyConfig(Phonebook[j] -> Config,i);
  410.                                                 }
  411.  
  412.                                                 Bits |= (1 << (i - GAD_SERIAL));
  413.  
  414.                                                 MadeChanges = TRUE;
  415.                                             }
  416.                                         }
  417.                                     }
  418.                                     else
  419.                                     {
  420.                                         for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
  421.                                         {
  422.                                             if(SZ_GetChecked(GadgetArray[i]))
  423.                                             {
  424.                                                 for(j = 0 ; j < NumPhoneEntries ; j++)
  425.                                                     CopyConfig(Phonebook[j] -> Config,i);
  426.  
  427.                                                 Bits |= (1 << (i - GAD_SERIAL));
  428.  
  429.                                                 MadeChanges = TRUE;
  430.                                             }
  431.                                         }
  432.                                     }
  433.                                 }
  434.                                 else
  435.                                 {
  436.                                     if(MyConfig)
  437.                                     {
  438.                                         for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
  439.                                         {
  440.                                             if(SZ_GetChecked(GadgetArray[i]))
  441.                                             {
  442.                                                 CopyConfig(MyConfig,i);
  443.  
  444.                                                 Bits |= (1 << (i - GAD_SERIAL));
  445.  
  446.                                                 MadeChanges = TRUE;
  447.                                             }
  448.                                         }
  449.                                     }
  450.                                 }
  451.  
  452.                                 Terminated = TRUE;
  453.  
  454.                                 break;
  455.  
  456.                             case GAD_CANCEL:
  457.  
  458.                                 Terminated = TRUE;
  459.                                 break;
  460.                         }
  461.                     }
  462.                 }
  463.             }
  464.  
  465.             RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  466.  
  467.             PopWindow();
  468.  
  469.             CloseWindow(PanelWindow);
  470.         }
  471.  
  472.         FreeGadgets(GadgetList);
  473.     }
  474.  
  475.     return(MadeChanges);
  476. }
  477.